using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Minio;
using Wiz.Minio.EventData;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class MinioFileServiceCollectionExtensions
    {
        /// <summary>
        /// 添加Minio文件下载服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IServiceCollection AddMinioFileService(this IServiceCollection services, IConfiguration configuration)
        {
            
                var section = configuration.GetSection(MinioOptions.SectionName);
                services.Configure<MinioOptions>(section);

                services.Configure<TaskAppOptions>(configuration.GetSection(TaskAppOptions.SectionName));                
                    
                services.AddMinio(configureClient => {    
                    var minioOptions = services.GetConfiguration().GetSection(MinioOptions.SectionName).Get<MinioOptions>();
                    configureClient
                    .WithEndpoint(minioOptions.Endpoint)
                    .WithCredentials(minioOptions.AccessKey, minioOptions.SecretKey)
                    .WithSSL(minioOptions.UseSSL)
                    .Build();
                    }
                );

                return services;
        }
    }
}